package com.briup.ch09;

/**
 * @Author briup-adam
 * @Date 2023/10/18 上午9:08
 * @Description
 **/

public class FinallyTest {
    public static void methodA() {
        int a = 10;
        try {
            a = 11;
        } catch (Exception e) {
            a = 12;
        } finally {
            //最后执行
            a = 13;
        }
        System.out.println(a);
    }

    public static int methodB() {
        int a = 10;
        try {
            a = 11;
        } catch (Exception e) {
            a = 12;
        } finally {
            //最后执行
            a = 13;
        }
        return a;
    }

    public static int methodC() {
        int a = 10;
        try {
            a = 11;
            return a;
        } catch (Exception e) {
            a = 12;
            return a;
        } finally {
//            执行了
            a = 13;
            System.out.println("a = " + a);
        }
    }

    public static int methodD() {
        int a = 10;
        try {
            a = 11;
            return a;
        } catch (Exception e) {
            a = 12;
            return a;
        } finally {
//            执行了
            a = 13;
            return  a;
        }
    }

    public static int methodE() {
        int a = 10;
        try {
            a = 11/0;
        } catch (Exception e) {
            a = 12;
            return a;
        } finally {
//            执行了
            a = 13;

        }
        return  a;
    }

    public static void main(String[] args) {
        methodA();
        System.out.println(methodB());
        System.out.println(methodC());
        System.out.println(methodD());
        System.out.println(methodE());
    }

}
